package com.lzh.runke.core.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lzh.runke.core.web_base.constant.StringConstant;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @Description:
 * @Author: LiuZiHao
 * @Date: 2022/6/15 10:25
 */
public class FileInfo extends BaseEntity {
    private static final long serialVersionUID = -7352349203687471799L;
    protected String filename;
    protected String originalName;
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    protected Date uploadDate;
    protected long fileSize;
    protected Boolean relatedFlag = false;
    private String username;

    public FileInfo() {
    }

    public FileInfo(String filename) {
        this.filename = filename;
        if (StringUtils.isNotBlank(filename)) {
            this.id = StringUtils.substringBefore(filename, StringConstant.COMMA);
        }

    }

    protected FileInfo(FileInfoBuilder<?, ?> b) {
        super(b);
        this.filename = b.filename;
        this.originalName = b.originalName;
        this.uploadDate = b.uploadDate;
        this.fileSize = b.fileSize;
        this.relatedFlag = b.relatedFlag;
        this.username = b.username;
    }

    public static FileInfoBuilder<?, ?> builder() {
        return new FileInfoBuilderImpl();
    }

    public String getFilename() {
        return this.filename;
    }

    public String getOriginalName() {
        return this.originalName;
    }

    public Date getUploadDate() {
        return this.uploadDate;
    }

    public long getFileSize() {
        return this.fileSize;
    }

    public Boolean getRelatedFlag() {
        return this.relatedFlag;
    }

    public String getUsername() {
        return this.username;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public void setOriginalName(String originalName) {
        this.originalName = originalName;
    }

    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    public void setUploadDate(Date uploadDate) {
        this.uploadDate = uploadDate;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public void setRelatedFlag(Boolean relatedFlag) {
        this.relatedFlag = relatedFlag;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    private static final class FileInfoBuilderImpl extends FileInfoBuilder<FileInfo, FileInfoBuilderImpl> {
        private FileInfoBuilderImpl() {
        }

        protected FileInfoBuilderImpl self() {
            return this;
        }

        public FileInfo build() {
            return new FileInfo(this);
        }
    }

    public abstract static class FileInfoBuilder<C extends FileInfo, B extends FileInfoBuilder<C, B>> extends BaseEntityBuilder<C, B> {
        private String filename;
        private String originalName;
        private Date uploadDate;
        private long fileSize;
        private Boolean relatedFlag;
        private String username;

        public FileInfoBuilder() {
        }

        protected abstract B self();

        public abstract C build();

        public B filename(String filename) {
            this.filename = filename;
            return this.self();
        }

        public B originalName(String originalName) {
            this.originalName = originalName;
            return this.self();
        }

        @JsonFormat(
                pattern = "yyyy-MM-dd HH:mm:ss"
        )
        public B uploadDate(Date uploadDate) {
            this.uploadDate = uploadDate;
            return this.self();
        }

        public B fileSize(long fileSize) {
            this.fileSize = fileSize;
            return this.self();
        }

        public B relatedFlag(Boolean relatedFlag) {
            this.relatedFlag = relatedFlag;
            return this.self();
        }

        public B username(String username) {
            this.username = username;
            return this.self();
        }

        public String toString() {
            return "FileInfo.FileInfoBuilder(super=" + super.toString() + ", filename=" + this.filename + ", originalName=" + this.originalName + ", uploadDate=" + this.uploadDate + ", fileSize=" + this.fileSize + ", relatedFlag=" + this.relatedFlag + ", username=" + this.username + ")";
        }
    }
}
